package com.example.text0926;

import android.content.Intent;
import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContract;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import androidx.activity.*;

public class MainActivity2 extends AppCompatActivity {
    Button button2_1;
    Button button2_2;
    TextView TextView4;
    private ActivityResultLauncher<Intent> someActivityResultLancher;

    @Override
    protected void onRestart() {
        super.onRestart();
        Log.d("mml","This is OnRestart!");
    }

    @Override
    protected void onPause() {
        super.onPause();
        Log.d("mml","This is OnPause!");
    }

    @Override
    protected void onResume() {
        super.onResume();
        Log.d("mml","This is OnResume!");
    }

    @Override
    protected void onStart() {
        super.onStart();
        Log.d("mml","This is OnStart!");
    }

    @Override
    protected void onStop() {
        super.onStop();
        Log.d("mml","This is OnStop!");
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        Log.d("mml","This is OnDestory!");
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        EdgeToEdge.enable(this);
        setContentView(R.layout.activity_main2);
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main), (v, insets) -> {
            Insets systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars());
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom);
            return insets;
        });
        Log.d("mml","This is OnCreate!");

        button2_1=findViewById(R.id.button2_1);
//        button2_2=findViewById(R.id.button2_2);
        someActivityResultLancher = registerForActivityResult(
                new ActivityResultContracts.StartActivityForResult(),
                new ActivityResultCallback<ActivityResult>() {
                    @Override
                    public void onActivityResult(ActivityResult result) {
                        if (result.getResultCode() == 666){
                            Intent data = result.getData();
//                            String resultData = data.getDataString("result");
                        }
                    }
                }
        );
        Intent intent=new Intent(this,MainActivity2_1.class);
        intent.putExtra("name","name:mml");
        intent.putExtra("age",21);
        //Bundle打包传输给A2_1
        Bundle bundle=new Bundle();
        bundle.putString("name","mml");
        bundle.putInt("age",21);
        intent.putExtras(bundle);

        button2_1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                startActivity(intent);
            }

        });
    }

}